﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using CH.Reia.Infrastructure.Domain;
using CH.Reia.Repository;
using CH.Reia.Entity;

namespace CH.Reia.Domain
{
    public class Domain : IDomain, IDisposable
    {
        private readonly Repository<Member> memberRepository;
        private readonly Repository<Link> linkRepository;

        private Domain(Repository<Member> dataRepository1, Repository<Link> dataRepository2)
        {
            this.memberRepository = dataRepository1;
            this.linkRepository = dataRepository2;
        }

        public static Domain CreateDomain()
        {
            return new Domain(Repository<Member>.CreateRepository(), Repository<Link>.CreateRepository());
        }

        public Domain()
            : base()
        {
            CreateDomain();
        }

        #region MemberRepository Members

        public List<Member> MemberLoad(Member loadEntity)
        {
            return this.memberRepository.Load(loadEntity);
        }

        public List<Member> MemberList(Member listEntity)
        {
            return this.memberRepository.List(listEntity);
        }

        public List<Member> MemberUpdate(Member updateEntity)
        {
            return this.memberRepository.Update(updateEntity);
        }

        public List<Member> MemberSave(Member saveEntity)
        {
            return this.memberRepository.Save(saveEntity);
        }

        public List<Member> MemberDelete(Member deleteEntity)
        {
            return this.memberRepository.Delete(deleteEntity);
        }

        public List<Member> MemberFind(Member findEntity)
        {
            return this.memberRepository.Find(findEntity);
        }

        #endregion

        #region LinkRepository Links

        public List<Link> LinkLoad(Link loadEntity)
        {
            return this.linkRepository.Load(loadEntity);
        }

        public List<Link> LinkList(Link listEntity)
        {
            return this.linkRepository.List(listEntity);
        }

        public List<Link> LinkUpdate(Link updateEntity)
        {
            return this.linkRepository.Update(updateEntity);
        }

        public List<Link> LinkSave(Link saveEntity)
        {
            return this.linkRepository.Save(saveEntity);
        }

        public List<Link> LinkDelete(Link deleteEntity)
        {
            return this.linkRepository.Delete(deleteEntity);
        }

        public List<Link> LinkFind(Link findEntity)
        {
            return this.linkRepository.Find(findEntity);
        }

        #endregion

        #region IDisposable Members

        public void Dispose()
        {
            if (this.memberRepository != null)
            {
                this.memberRepository.Dispose();
            }

            if (this.linkRepository != null)
            {
                this.linkRepository.Dispose();
            }
        }

        #endregion
    }
}
